package com.study.interceptor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.alibaba.fastjson.JSONObject;
import com.study.services.PermissionServices;
@Configuration
public class XiaoshouInterceptor extends HandlerInterceptorAdapter implements WebMvcConfigurer{
	PermissionServices perstion;
	/*
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("SimpleInterceptor的preHandle方法。。。。销售");
		boolean fag=false;
		String servletPath = request.getServletPath();
		System.out.println(servletPath+"                servletPath");
		//获取网址
		JSONObject setlectUrlcs = perstion.setlectUrlcs(servletPath);
		//获取角色id
		List<String> attribute = (List<String>) request.getSession().getAttribute("roleid");
		if(setlectUrlcs!=null&&setlectUrlcs.isEmpty()) {
			//获取网址文件
			String url_model = setlectUrlcs.getString("url_model");
			//获取网址父级id
			String url_supper = setlectUrlcs.getString("url_supper");
			for (String string : attribute) {
				//customer/addhighseas
				//获取对应的权限
				//List<JSONObject> getfidnPerstionroleid = perstion.getfidnPerstionroleid(string);
				System.out.println("juese      "+string);
				if(string.equals("1")) {
					fag=true;
				}else if(string.equals("7")) {
					fag=true;
				}else {
					fag=true;
					response.sendRedirect("/index");
				}
			}
		}
		return fag;
	}*/
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {/*
		System.out.println(modelAndView.getViewName()+"                      modelAndView");
		System.out.println("SimpleInterceptor的postHandle方法。。2。。销售");
	*/}
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {/*
		System.out.println("SimpleInterceptor的afterCompletion方法。。3。。销售");
	*/}
	
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {/*
		// TODO Auto-generated method stub
		WebMvcConfigurer.super.addInterceptors(registry);
		registry.addInterceptor(this).addPathPatterns("/afterSale/**",
				"/beforeSale/**","/customer/**","/depot/**","/getCustomer/**","/goods/**","/onSale/**","/permission/**");
	*/}
}
